package com.org.qrtrace.utils;
import com.alibaba.fastjson.JSON;


/**
 * Controller返回封装类
 */
public class JsonResult<T> {
    public static final int FAIL = 101;
    public static final int SUCCESS = 200;
    public static final Object SUCCESS_MSG = "成功";
    private int resCode;
    private String msg;
    private T info;

    public int getResCode() {
        return resCode;
    }

    public void setResCode(int resCode) {
        this.resCode = resCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getInfo() {
        return info;
    }

    public void setInfo(T info) {
        this.info = info;
    }

    public JsonResult(int resCode,String msg,T info){
        this.resCode = resCode;
        this.msg = msg;
        this.info = info;

    }

    public JsonResult(int resCode,String msg){
        this.resCode = resCode;
        this.msg = msg;
    }

    public static JsonResult success(){
        return new JsonResult(SUCCESS,"成功");
    }

    public static JsonResult success(String msg){
        return new JsonResult(SUCCESS,msg);
    }

    public static JsonResult successInfo(Object info){
        return new JsonResult(SUCCESS,"成功",info);
    }

    public static JsonResult success(String msg,Object info){
        return new JsonResult(SUCCESS,msg,info);
    }

    public static JsonResult fail(String msg){
        return new JsonResult(FAIL,msg);
    }

    public static JsonResult fail(int errorCode,String msg){
        return new JsonResult(errorCode,msg);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}

